package me.pinion.kit;

import com.jfinal.kit.PathKit;
import me.pinion.Log;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropKit {
    private static Map<String, Properties> PROPS = new HashMap<String, Properties>();

    public static Properties get(String filename){
        if(PROPS.get(filename) == null){
            Properties prop = new Properties();
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(PathKit.getRootClassPath() + "/" + filename + ".properties");
                prop.load(fis);
                PROPS.put(filename, prop);
            } catch (FileNotFoundException e) {
                Log.e(e);
            } catch (IOException e) {
                Log.e(e);
            }
        }
        return PROPS.get(filename);
    }

    public static String get(String properties, String key){
        return PropKit.get(properties).getProperty(key);
    }
}
